package com.xpffly.design.prototype;

import cn.hutool.core.util.RandomUtil;
import com.xpffly.design.prototype.service.AdviceTemplate;
import com.xpffly.design.prototype.service.Mail;

/**
 * @Author: xpengfei
 * @Date: 2021/4/3 16:06
 * @Description：原型模式场景类
 */
public class Scene {
    /**
     * 发送账单的数量
     */
    private static int MAIL_NUM = 10;

    public static void main(String[] args) throws CloneNotSupportedException {
        // 定义模板
        Mail mail = new Mail(new AdviceTemplate());
        mail.setTail("XXX银行版权所有");
        for (int i = 0; i < MAIL_NUM; i++) {
            // 以下是没封邮件不同的地方
            Mail cloneMail = mail.clone();
            cloneMail.setAppellation(RandomUtil.randomString(8) + "先生（女士）");
            cloneMail.setReceiver(RandomUtil.randomString(11) + "@" + RandomUtil.randomString(3) + ".com");
            // 发送邮件
            sendMail(cloneMail);
        }
    }

    /**
     * 发送邮件
     *
     * @param mail
     */
    public static void sendMail(Mail mail) {
        System.out.println("邮件主题：" + mail.getSubject() +
                "\n收件人：" + mail.getReceiver() +
                "\n称谓：" + mail.getAppellation() +
                "\n邮件内容：" + mail.getContext() +
                "\n邮件尾部信息：" + mail.getTail());
        System.out.println("***********--------------*************");
    }
}
